package com.foxzzz.base;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

public class ArrayUtil {
    public static void visit(int[] array) {
        for (int i : array) {
            System.out.print(i + " ");
        }
        System.out.println("");
    }

    public static int[][] toIntArray2D(String arrayStr) {
        JSONArray objects = JSON.parseArray(arrayStr);
        int height = objects.size();
        int weight = 0;
        if (height == 0) {
            return new int[0][0];
        } else {
            JSONArray objects1 = (JSONArray) objects.get(0);
            weight = objects1.size();
            if (weight == 0) {
                return new int[height][0];
            }
            int[][] res = new int[height][weight];
            for (int i = 0; i < objects.size(); i++) {
                JSONArray line = (JSONArray) objects.get(i);
                for (int j = 0; j < line.size(); j++) {
                    res[i][j] = (int) line.get(j);
                }
            }
            return res;
        }
    }

    public static int[] generator(int... array) {
        return array;
    }
}
